package Boundry;


import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import Boundry.GenericTools.IPanelOperation;
import Boundry.GenericTools.InputPanel;
import Controllers.GlobalData;
import Controllers.ICMManagerController;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import net.sourceforge.jdatepicker.impl.JDatePanelImpl;
import net.sourceforge.jdatepicker.DateModel;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import java.awt.Font;

public class SatisticalReportPanel extends InputPanel implements IPanelOperation {
	private JButton btnActivityReport;
	private JButton btnOpreationReport;
	private JButton btnDelayReport;
	private JComboBox comboBoxPastReports;
	private JDatePanelImpl datePanelFrom;
	private JDatePanelImpl datePanelTo;
	private JButton btnDisplayPastReports;

	/**
	 * Create the panel.
	 */
	public SatisticalReportPanel() {
		init();
	
		
	}

	
	
	private void init()
	{
		JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
		tabbedPane.setBounds(35, 11, 786, 337);
		mainPanel.add(tabbedPane);
		
		JPanel panel = new JPanel();
		tabbedPane.addTab("Activity Report", null, panel, null);
		panel.setLayout(null);
		
		JPanel panel_3 = new JPanel();
		panel_3.setBounds(42, 11, 690, 276);
		panel.add(panel_3);
		panel_3.setLayout(null);
		
		datePanelFrom = new JDatePanelImpl((DateModel) null);
		datePanelFrom.setBounds(33, 35, 200, 180);
		panel_3.add(datePanelFrom);
		
		datePanelTo = new JDatePanelImpl((DateModel) null);
		datePanelTo.setBounds(457, 35, 200, 180);
		panel_3.add(datePanelTo);
		
		JLabel lblFrom = new JLabel("From:");
		lblFrom.setFont(new Font("Tahoma", Font.BOLD, 11));
		lblFrom.setBounds(34, 10, 46, 14);
		panel_3.add(lblFrom);
		
		JLabel lblTo = new JLabel("To:");
		lblTo.setFont(new Font("Tahoma", Font.BOLD, 11));
		lblTo.setBounds(457, 10, 46, 14);
		panel_3.add(lblTo);
		
		btnActivityReport = new JButton("Activity Report");
		btnActivityReport.setBounds(279, 213, 124, 63);
		panel_3.add(btnActivityReport);
		
		JPanel panel_1 = new JPanel();
		tabbedPane.addTab("Opreation Report", null, panel_1, null);
		panel_1.setLayout(null);
		
		btnOpreationReport = new JButton("Opreation Report");
		btnOpreationReport.setBounds(235, 120, 124, 63);
		panel_1.add(btnOpreationReport);
		
		JPanel panel_2 = new JPanel();
		tabbedPane.addTab("Delay Report", null, panel_2, null);
		panel_2.setLayout(null);
		
		btnDelayReport = new JButton("Delay Report");
		btnDelayReport.setBounds(192, 118, 124, 63);
		panel_2.add(btnDelayReport);
		
		JPanel panel_4 = new JPanel();
		tabbedPane.addTab("Past Activity Report", null, panel_4, null);
		panel_4.setLayout(null);
		
		comboBoxPastReports = new JComboBox();
		comboBoxPastReports.setBounds(145, 92, 268, 20);
		panel_4.add(comboBoxPastReports);
		
		JLabel lblPastReport = new JLabel("Past Report:");
		lblPastReport.setBounds(145, 56, 123, 14);
		panel_4.add(lblPastReport);
		
		btnDisplayPastReports = new JButton("Display Past Reports");
		btnDisplayPastReports.setBounds(190, 152, 182, 23);
		panel_4.add(btnDisplayPastReports);

		
		
		
		
		
	}
	public JButton getBtnDisplayPastReports() {
		return btnDisplayPastReports;
	}



	public void setBtnDisplayPastReports(JButton btnDisplayPastReports) {
		this.btnDisplayPastReports = btnDisplayPastReports;
	}



	public JButton getBtnActivityReport() {
		return btnActivityReport;
	}

	public void setBtnActivityReport(JButton btnActivityReport) {
		this.btnActivityReport = btnActivityReport;
	}

	public JButton getBtnOpreationReport() {
		return btnOpreationReport;
	}

	public void setBtnOpreationReport(JButton btnOpreationReport) {
		this.btnOpreationReport = btnOpreationReport;
	}

	public JButton getBtnDelayReport() {
		return btnDelayReport;
	}

	public void setBtnDelayReport(JButton btnDelayReport) {
		this.btnDelayReport = btnDelayReport;
	}

	public JComboBox getComboBoxPastReports() {
		return comboBoxPastReports;
	}

	public void setComboBoxPastReports(JComboBox comboBoxPastReports) {
		this.comboBoxPastReports = comboBoxPastReports;
	}

	public JDatePanelImpl getDatePanelFrom() {
		return datePanelFrom;
	}

	public void setDatePanelFrom(JDatePanelImpl datePanelFrom) {
		this.datePanelFrom = datePanelFrom;
	}

	public JDatePanelImpl getDatePanelTo() {
		return datePanelTo;
	}

	public void setDatePanelTo(JDatePanelImpl datePanelTo) {
		this.datePanelTo = datePanelTo;
	}
	
	
	
	
	public Date getDateFrom(){
		
		
		DateModel datemod = this.datePanelFrom.getModel();
		Calendar cal = Calendar.getInstance();
		cal.set(datemod.getYear(), datemod.getMonth(), datemod.getDay());
		Date datesql  = cal.getTime();
	//	@SuppressWarnings("deprecation")
	//	Date datesql = new Date(datemod.getDay(),datemod.getMonth()+1,datemod.getYear());
		
		//System.out.println(datesql.toString());
		
		return datesql;
		
	}
	

	public Date getDateTo(){
		Calendar cal = Calendar.getInstance();
		DateModel datemod = this.datePanelTo.getModel();
		cal.set(datemod.getYear(), datemod.getMonth(), datemod.getDay());
		Date datesql  = cal.getTime();
//		@SuppressWarnings("deprecation")
		
	//	Date datesql = new Date(new Date().UTC(datemod.getYear(), datemod.getMonth()+1, datemod.getDay(), 0, 0, 0));
	//	datesql.setYear(datemod.getYear());
	//	datesql.setMonth(datemod.getMonth()+1);
	//	datesql.setDate(datemod.getDay());
	//	System.out.println(datemod.getYear());
	///	System.out.println(datemod.getMonth());
	//	System.out.println(datemod.getDay());

		System.out.println(datesql.toString());

		
		return datesql;
		
	}
	
	public boolean isValidDates(){
		
		Date today = new java.util.Date();
		 Date sqlToday = new java.sql.Date(today.getTime());
		
		if ( ( sqlToday.before(getDateFrom())==true) &&   (sqlToday.before(getDateTo())==true)  )
		{
			return false;
		}
		else{
			if ( getDateFrom().before( getDateTo())==true)
				return true;
			else
				return false;
		}
		
	}



	@Override
	public String apHelpButton() {
 		 return "Here the ICM manager can review statistic data about the system";
	}



	@Override
	public String setTitle() {	
		return "Statistical Reports";
	}



	public void addlisteners(ICMManagerController icmManagerController) 
	{
		    btnActivityReport.addActionListener(icmManagerController);
		    btnDelayReport.addActionListener(icmManagerController);
		    btnDisplayPastReports.addActionListener(icmManagerController);
		    btnOpreationReport.addActionListener(icmManagerController);
	}
	
	
	
	
	
}
